{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5b33a40d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#匿名函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ba0e831e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_func = lambda x: 2*x\n",
    "    \n",
    "my_func(3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c5cd0cd1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multi_para_func = lambda a,b:a + b\n",
    "\n",
    "multi_para_func(1, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a1e891b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[(lambda x : 2*x)(i) for i in range(5)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ebc1bebf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x: 2*x,range(5)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "43a5b634",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小明_18', '小红_19', '丽华_20']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#学生练习\n",
    "name = ['小明','小红','丽华']\n",
    "age = [18,19,20]\n",
    "\n",
    "#希望得到效果：\n",
    "['小明_18','小红_19','丽华_20']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "20d5ec5d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小明_18\n",
      "小明_19\n",
      "小明_20\n",
      "小红_18\n",
      "小红_19\n",
      "小红_20\n",
      "丽华_18\n",
      "丽华_19\n",
      "丽华_20\n"
     ]
    }
   ],
   "source": [
    "#错误示范\n",
    "for i in name:\n",
    "    for j in age:\n",
    "        print(i+'_'+str(j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9deaf6f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['小明_18', '小红_19', '丽华_20']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#正确做法\n",
    "list(map(lambda x,y:x+'_'+str(y),name,age))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "7db146f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j')]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#zip对象与enumerate\n",
    "L1,L2,L3 = list('abc'), list('def'), list('hij')\n",
    "\n",
    "list(zip(L1,L2,L3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7bd80c9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(('a', 'd', 'h'), ('b', 'e', 'i'), ('c', 'f', 'j'))"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tuple(zip(L1,L2,L3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "07d16a4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a d h\n",
      "b e i\n",
      "c f j\n"
     ]
    }
   ],
   "source": [
    "for i ,j, k in zip(L1,L2,L3):\n",
    "    print(i,j,k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "d855e7b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "#文件读取\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "69199a04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col1</th>\n",
       "      <th>col2</th>\n",
       "      <th>col3</th>\n",
       "      <th>col4</th>\n",
       "      <th>col5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>a</td>\n",
       "      <td>1.4</td>\n",
       "      <td>apple</td>\n",
       "      <td>2020/1/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>b</td>\n",
       "      <td>3.4</td>\n",
       "      <td>banana</td>\n",
       "      <td>2020/1/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>c</td>\n",
       "      <td>2.5</td>\n",
       "      <td>orange</td>\n",
       "      <td>2020/1/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5</td>\n",
       "      <td>d</td>\n",
       "      <td>3.2</td>\n",
       "      <td>lemon</td>\n",
       "      <td>2020/1/7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   col1 col2  col3    col4      col5\n",
       "0     2    a   1.4   apple  2020/1/1\n",
       "1     3    b   3.4  banana  2020/1/2\n",
       "2     6    c   2.5  orange  2020/1/5\n",
       "3     5    d   3.2   lemon  2020/1/7"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('C:/Users/pc/Desktop/data_analysis-master/week02/data/my_csv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b12177e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
